/*     */ package com.zimbra.qa.unittest.prov.ldap;
/*     */ 
/*     */ import com.google.common.collect.Lists;
/*     */ import com.zimbra.common.account.Key.DistributionListBy;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.DistributionList;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.accesscontrol.CollectAllEffectiveRights;
/*     */ import com.zimbra.cs.account.accesscontrol.CollectAllEffectiveRights.AllGroupMembers;
/*     */ import com.zimbra.cs.account.accesscontrol.CollectAllEffectiveRights.GroupShape;
/*     */ import com.zimbra.cs.account.accesscontrol.GranteeType;
/*     */ import com.zimbra.cs.account.accesscontrol.Right;
/*     */ import com.zimbra.cs.account.accesscontrol.RightCommand;
/*     */ import com.zimbra.cs.account.accesscontrol.RightModifier;
/*     */ import com.zimbra.cs.account.accesscontrol.Rights.Admin;
/*     */ import com.zimbra.cs.account.accesscontrol.TargetType;
/*     */ import com.zimbra.cs.account.ldap.LdapProv;
/*     */ import com.zimbra.qa.unittest.prov.Verify;
/*     */ import com.zimbra.soap.admin.type.GranteeSelector.GranteeBy;
/*     */ import com.zimbra.soap.type.TargetBy;
/*     */ import java.io.PrintStream;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Collections;
/*     */ import java.util.HashSet;
/*     */ import java.util.List;
/*     */ import java.util.Set;
/*     */ import org.junit.AfterClass;
/*     */ import org.junit.BeforeClass;
/*     */ import org.junit.Test;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestACLAllEffRights
/*     */   extends LdapTest
/*     */ {
/*     */   private static LdapProvTestUtil provUtil;
/*     */   private static LdapProv prov;
/*     */   
/*     */   @BeforeClass
/*     */   public static void init()
/*     */     throws Exception
/*     */   {
/*  55 */     provUtil = new LdapProvTestUtil();
/*  56 */     prov = provUtil.getProv();
/*     */   }
/*     */   
/*     */   @AfterClass
/*     */   public static void cleanup() throws Exception {
/*  61 */     Cleanup.deleteAll(new String[] { baseDomainName() });
/*     */   }
/*     */   
/*     */   private CollectAllEffectiveRights.AllGroupMembers allGroupMembers(DistributionList dl) throws ServiceException {
/*  65 */     CollectAllEffectiveRights caer = new CollectAllEffectiveRights(null, false, false, null);
/*  66 */     return caer.getAllGroupMembers(dl);
/*     */   }
/*     */   
/*     */ 
/*     */   @Test
/*     */   public void shapeTest1()
/*     */     throws Exception
/*     */   {
/*  74 */     String domainName = genDomainName(baseDomainName());
/*     */     
/*  76 */     Domain domain = provUtil.createDomain(domainName);
/*     */     
/*  78 */     DistributionList groupA = provUtil.createDistributionList("groupA", domain);
/*  79 */     DistributionList groupB = provUtil.createDistributionList("groupB", domain);
/*  80 */     DistributionList groupC = provUtil.createDistributionList("groupC", domain);
/*  81 */     DistributionList groupD = provUtil.createDistributionList("groupD", domain);
/*     */     
/*  83 */     Account A = provUtil.createAccount("A", domain);
/*  84 */     Account B = provUtil.createAccount("B", domain);
/*  85 */     Account C = provUtil.createAccount("C", domain);
/*  86 */     Account D = provUtil.createAccount("D", domain);
/*  87 */     Account AB = provUtil.createAccount("AB", domain);
/*  88 */     Account AC = provUtil.createAccount("AC", domain);
/*  89 */     Account AD = provUtil.createAccount("AD", domain);
/*  90 */     Account BC = provUtil.createAccount("BC", domain);
/*  91 */     Account BD = provUtil.createAccount("BD", domain);
/*  92 */     Account CD = provUtil.createAccount("CD", domain);
/*  93 */     Account ABC = provUtil.createAccount("ABC", domain);
/*  94 */     Account ABD = provUtil.createAccount("ABD", domain);
/*  95 */     Account ACD = provUtil.createAccount("ACD", domain);
/*  96 */     Account BCD = provUtil.createAccount("BCD", domain);
/*  97 */     Account ABCD = provUtil.createAccount("ABCD", domain);
/*     */     
/*  99 */     groupA.addMembers(new String[] { A.getName(), AB.getName(), AC.getName(), AD.getName(), ABC.getName(), ABD.getName(), ACD.getName(), ABCD.getName() });
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 104 */     groupB.addMembers(new String[] { B.getName(), AB.getName(), BC.getName(), BD.getName(), ABC.getName(), ABD.getName(), BCD.getName(), ABCD.getName() });
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 109 */     groupC.addMembers(new String[] { C.getName(), AC.getName(), BC.getName(), CD.getName(), ABC.getName(), ACD.getName(), BCD.getName(), ABCD.getName() });
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 114 */     groupD.addMembers(new String[] { D.getName(), AD.getName(), BD.getName(), CD.getName(), ABD.getName(), ACD.getName(), BCD.getName(), ABCD.getName() });
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 123 */     Set<DistributionList> groupsWithGrants = new HashSet();
/* 124 */     groupsWithGrants.add(groupA);
/* 125 */     groupsWithGrants.add(groupB);
/* 126 */     groupsWithGrants.add(groupC);
/* 127 */     groupsWithGrants.add(groupD);
/*     */     
/* 129 */     Set<CollectAllEffectiveRights.GroupShape> accountShapes = new HashSet();
/* 130 */     Set<CollectAllEffectiveRights.GroupShape> calendarResourceShapes = new HashSet();
/* 131 */     Set<CollectAllEffectiveRights.GroupShape> distributionListShapes = new HashSet();
/*     */     
/* 133 */     for (DistributionList group : groupsWithGrants) {
/* 134 */       DistributionList dl = prov.get(Key.DistributionListBy.id, group.getId());
/* 135 */       CollectAllEffectiveRights.AllGroupMembers allMembers = allGroupMembers(dl);
/* 136 */       CollectAllEffectiveRights.GroupShape.shapeMembers(TargetType.account, accountShapes, allMembers);
/* 137 */       CollectAllEffectiveRights.GroupShape.shapeMembers(TargetType.calresource, calendarResourceShapes, allMembers);
/* 138 */       CollectAllEffectiveRights.GroupShape.shapeMembers(TargetType.dl, distributionListShapes, allMembers);
/*     */     }
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 145 */     Set<String> result = new HashSet();
/* 146 */     int count = 1;
/* 147 */     for (CollectAllEffectiveRights.GroupShape shape : accountShapes) {
/* 148 */       List<String> elements = new ArrayList();
/*     */       
/* 150 */       System.out.println("\n" + count++);
/* 151 */       for (String group : shape.getGroups()) {
/* 152 */         System.out.println("group " + group);
/* 153 */         elements.add("group " + group);
/*     */       }
/* 155 */       for (String member : shape.getMembers()) {
/* 156 */         System.out.println("    member" + member);
/* 157 */         elements.add("member " + member);
/*     */       }
/* 159 */       Collections.sort(elements);
/*     */       
/*     */ 
/*     */ 
/*     */ 
/* 164 */       if (shape.getMembers().size() > 0) {
/* 165 */         result.add(Verify.makeResultStr(new Object[] { elements }));
/*     */       }
/*     */     }
/*     */     
/* 169 */     Set<String> expected = new HashSet();
/* 170 */     expected.add(Verify.makeResultStr(new Object[] { Lists.newArrayList(new String[] { "group " + groupA.getName(), "member " + A.getName() }) }));
/*     */     
/*     */ 
/* 173 */     expected.add(Verify.makeResultStr(new Object[] { Lists.newArrayList(new String[] { "group " + groupB.getName(), "member " + B.getName() }) }));
/*     */     
/*     */ 
/* 176 */     expected.add(Verify.makeResultStr(new Object[] { Lists.newArrayList(new String[] { "group " + groupC.getName(), "member " + C.getName() }) }));
/*     */     
/*     */ 
/* 179 */     expected.add(Verify.makeResultStr(new Object[] { Lists.newArrayList(new String[] { "group " + groupD.getName(), "member " + D.getName() }) }));
/*     */     
/*     */ 
/* 182 */     expected.add(Verify.makeResultStr(new Object[] { Lists.newArrayList(new String[] { "group " + groupA.getName(), "group " + groupB.getName(), "member " + AB.getName() }) }));
/*     */     
/*     */ 
/*     */ 
/* 186 */     expected.add(Verify.makeResultStr(new Object[] { Lists.newArrayList(new String[] { "group " + groupA.getName(), "group " + groupC.getName(), "member " + AC.getName() }) }));
/*     */     
/*     */ 
/*     */ 
/* 190 */     expected.add(Verify.makeResultStr(new Object[] { Lists.newArrayList(new String[] { "group " + groupA.getName(), "group " + groupD.getName(), "member " + AD.getName() }) }));
/*     */     
/*     */ 
/*     */ 
/* 194 */     expected.add(Verify.makeResultStr(new Object[] { Lists.newArrayList(new String[] { "group " + groupB.getName(), "group " + groupC.getName(), "member " + BC.getName() }) }));
/*     */     
/*     */ 
/*     */ 
/* 198 */     expected.add(Verify.makeResultStr(new Object[] { Lists.newArrayList(new String[] { "group " + groupB.getName(), "group " + groupD.getName(), "member " + BD.getName() }) }));
/*     */     
/*     */ 
/*     */ 
/* 202 */     expected.add(Verify.makeResultStr(new Object[] { Lists.newArrayList(new String[] { "group " + groupC.getName(), "group " + groupD.getName(), "member " + CD.getName() }) }));
/*     */     
/*     */ 
/*     */ 
/* 206 */     expected.add(Verify.makeResultStr(new Object[] { Lists.newArrayList(new String[] { "group " + groupA.getName(), "group " + groupB.getName(), "group " + groupC.getName(), "member " + ABC.getName() }) }));
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 211 */     expected.add(Verify.makeResultStr(new Object[] { Lists.newArrayList(new String[] { "group " + groupA.getName(), "group " + groupB.getName(), "group " + groupD.getName(), "member " + ABD.getName() }) }));
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 216 */     expected.add(Verify.makeResultStr(new Object[] { Lists.newArrayList(new String[] { "group " + groupA.getName(), "group " + groupC.getName(), "group " + groupD.getName(), "member " + ACD.getName() }) }));
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 221 */     expected.add(Verify.makeResultStr(new Object[] { Lists.newArrayList(new String[] { "group " + groupB.getName(), "group " + groupC.getName(), "group " + groupD.getName(), "member " + BCD.getName() }) }));
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 226 */     expected.add(Verify.makeResultStr(new Object[] { Lists.newArrayList(new String[] { "group " + groupA.getName(), "group " + groupB.getName(), "group " + groupC.getName(), "group " + groupD.getName(), "member " + ABCD.getName() }) }));
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 233 */     Verify.verifyEquals(expected, result);
/*     */   }
/*     */   
/*     */ 
/*     */   @Test
/*     */   public void shapeTest2()
/*     */     throws Exception
/*     */   {
/* 241 */     String domainName = genDomainName(baseDomainName());
/*     */     
/* 243 */     Domain domain = provUtil.createDomain(domainName);
/*     */     
/* 245 */     DistributionList groupA = provUtil.createDistributionList("groupA", domain);
/* 246 */     DistributionList groupB = provUtil.createDistributionList("groupB", domain);
/* 247 */     DistributionList groupC = provUtil.createDistributionList("groupC", domain);
/* 248 */     DistributionList groupD = provUtil.createDistributionList("groupD", domain);
/*     */     
/* 250 */     Account A = provUtil.createAccount("A", domain);
/* 251 */     Account B = provUtil.createAccount("B", domain);
/* 252 */     Account C = provUtil.createAccount("C", domain);
/* 253 */     Account D = provUtil.createAccount("D", domain);
/*     */     
/* 255 */     groupA.addMembers(new String[] { A.getName(), groupB.getName() });
/* 256 */     groupB.addMembers(new String[] { B.getName(), groupC.getName() });
/* 257 */     groupC.addMembers(new String[] { C.getName(), groupD.getName() });
/* 258 */     groupD.addMembers(new String[] { D.getName() });
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 263 */     Set<DistributionList> groupsWithGrants = new HashSet();
/* 264 */     groupsWithGrants.add(groupA);
/* 265 */     groupsWithGrants.add(groupB);
/* 266 */     groupsWithGrants.add(groupC);
/* 267 */     groupsWithGrants.add(groupD);
/*     */     
/* 269 */     Set<CollectAllEffectiveRights.GroupShape> accountShapes = new HashSet();
/* 270 */     Set<CollectAllEffectiveRights.GroupShape> calendarResourceShapes = new HashSet();
/* 271 */     Set<CollectAllEffectiveRights.GroupShape> distributionListShapes = new HashSet();
/*     */     
/* 273 */     for (DistributionList group : groupsWithGrants) {
/* 274 */       DistributionList dl = prov.get(Key.DistributionListBy.id, group.getId());
/* 275 */       CollectAllEffectiveRights.AllGroupMembers allMembers = allGroupMembers(dl);
/* 276 */       CollectAllEffectiveRights.GroupShape.shapeMembers(TargetType.account, accountShapes, allMembers);
/* 277 */       CollectAllEffectiveRights.GroupShape.shapeMembers(TargetType.calresource, calendarResourceShapes, allMembers);
/* 278 */       CollectAllEffectiveRights.GroupShape.shapeMembers(TargetType.dl, distributionListShapes, allMembers);
/*     */     }
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 284 */     Set<String> result = new HashSet();
/* 285 */     int count = 1;
/* 286 */     for (CollectAllEffectiveRights.GroupShape shape : accountShapes) {
/* 287 */       List<String> elements = new ArrayList();
/*     */       
/* 289 */       System.out.println("\n" + count++);
/* 290 */       for (String group : shape.getGroups()) {
/* 291 */         System.out.println("group " + group);
/* 292 */         elements.add("group " + group);
/*     */       }
/* 294 */       for (String member : shape.getMembers()) {
/* 295 */         System.out.println("    " + member);
/* 296 */         elements.add("member " + member);
/*     */       }
/* 298 */       Collections.sort(elements);
/*     */       
/*     */ 
/*     */ 
/*     */ 
/* 303 */       if (shape.getMembers().size() > 0) {
/* 304 */         result.add(Verify.makeResultStr(new Object[] { elements }));
/*     */       }
/*     */     }
/*     */     
/* 308 */     Set<String> expected = new HashSet();
/* 309 */     expected.add(Verify.makeResultStr(new Object[] { Lists.newArrayList(new String[] { "group " + groupA.getName(), "member " + A.getName() }) }));
/*     */     
/*     */ 
/* 312 */     expected.add(Verify.makeResultStr(new Object[] { Lists.newArrayList(new String[] { "group " + groupA.getName(), "group " + groupB.getName(), "member " + B.getName() }) }));
/*     */     
/*     */ 
/*     */ 
/* 316 */     expected.add(Verify.makeResultStr(new Object[] { Lists.newArrayList(new String[] { "group " + groupA.getName(), "group " + groupB.getName(), "group " + groupC.getName(), "member " + C.getName() }) }));
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 321 */     expected.add(Verify.makeResultStr(new Object[] { Lists.newArrayList(new String[] { "group " + groupA.getName(), "group " + groupB.getName(), "group " + groupC.getName(), "group " + groupD.getName(), "member " + D.getName() }) }));
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 328 */     Verify.verifyEquals(expected, result);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   @Test
/*     */   public void disinheritSubGroupModifier()
/*     */     throws Exception
/*     */   {
/* 375 */     String domainName = genDomainName(baseDomainName());
/*     */     
/* 377 */     Domain domain = provUtil.createDomain(domainName);
/*     */     
/*     */ 
/* 380 */     DistributionList dl = provUtil.createDistributionList("dl", domain);
/* 381 */     DistributionList subdl = provUtil.createDistributionList("subdl", domain);
/* 382 */     DistributionList subsubdl = provUtil.createDistributionList("subsubdl", domain);
/*     */     
/*     */ 
/* 385 */     Account a_dl = provUtil.createAccount("a_dl", domain);
/* 386 */     Account a_subdl = provUtil.createAccount("a_subdl", domain);
/* 387 */     Account a_subsubdl = provUtil.createAccount("a_subsubdl", domain);
/*     */     
/*     */ 
/* 390 */     Account da1 = provUtil.createDelegatedAdmin("da1", domain);
/* 391 */     Account da2 = provUtil.createDelegatedAdmin("da2", domain);
/*     */     
/* 393 */     dl.addMembers(new String[] { subdl.getName(), a_dl.getName() });
/* 394 */     subdl.addMembers(new String[] { subsubdl.getName(), a_subdl.getName() });
/* 395 */     subsubdl.addMembers(new String[] { a_subsubdl.getName() });
/*     */     
/* 397 */     Right DL_RESET_RIGHT = Rights.Admin.R_addDistributionListMember;
/* 398 */     Right DL_ATTR_RIGHT = Rights.Admin.R_modifyDistributionList;
/* 399 */     Right ACCT_PRESET_RIGHT = Rights.Admin.R_listAccount;
/* 400 */     Right ACCT_ATTR_RIGHT = Rights.Admin.R_modifyAccount;
/*     */     
/* 402 */     RightCommand.grantRight(prov, null, TargetType.dl.getCode(), TargetBy.name, dl.getName(), GranteeType.GT_USER.getCode(), GranteeSelector.GranteeBy.name, da1.getName(), null, DL_RESET_RIGHT.getName(), null);
/*     */     
/*     */ 
/*     */ 
/* 406 */     RightCommand.grantRight(prov, null, TargetType.dl.getCode(), TargetBy.name, dl.getName(), GranteeType.GT_USER.getCode(), GranteeSelector.GranteeBy.name, da1.getName(), null, DL_ATTR_RIGHT.getName(), null);
/*     */     
/*     */ 
/*     */ 
/* 410 */     RightCommand.grantRight(prov, null, TargetType.dl.getCode(), TargetBy.name, dl.getName(), GranteeType.GT_USER.getCode(), GranteeSelector.GranteeBy.name, da1.getName(), null, ACCT_PRESET_RIGHT.getName(), null);
/*     */     
/*     */ 
/*     */ 
/* 414 */     RightCommand.grantRight(prov, null, TargetType.dl.getCode(), TargetBy.name, dl.getName(), GranteeType.GT_USER.getCode(), GranteeSelector.GranteeBy.name, da1.getName(), null, ACCT_ATTR_RIGHT.getName(), null);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 419 */     RightCommand.grantRight(prov, null, TargetType.dl.getCode(), TargetBy.name, dl.getName(), GranteeType.GT_USER.getCode(), GranteeSelector.GranteeBy.name, da2.getName(), null, DL_RESET_RIGHT.getName(), RightModifier.RM_DENY);
/*     */     
/*     */ 
/*     */ 
/* 423 */     RightCommand.grantRight(prov, null, TargetType.dl.getCode(), TargetBy.name, dl.getName(), GranteeType.GT_USER.getCode(), GranteeSelector.GranteeBy.name, da2.getName(), null, DL_ATTR_RIGHT.getName(), RightModifier.RM_DENY);
/*     */     
/*     */ 
/*     */ 
/* 427 */     RightCommand.grantRight(prov, null, TargetType.dl.getCode(), TargetBy.name, dl.getName(), GranteeType.GT_USER.getCode(), GranteeSelector.GranteeBy.name, da2.getName(), null, ACCT_PRESET_RIGHT.getName(), RightModifier.RM_DENY);
/*     */     
/*     */ 
/*     */ 
/* 431 */     RightCommand.grantRight(prov, null, TargetType.dl.getCode(), TargetBy.name, dl.getName(), GranteeType.GT_USER.getCode(), GranteeSelector.GranteeBy.name, da2.getName(), null, ACCT_ATTR_RIGHT.getName(), RightModifier.RM_DENY);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/prov/ldap/TestACLAllEffRights.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */